//将一个表单的数据返回成JSON对象 
$.fn.serializeObject = function() {	
  var o = {};  
  var a = this.serializeArray();  
  $.each(a, function() {  
    if (o[this.name]) {  
      if (!o[this.name].push) {  
        o[this.name] = [ o[this.name] ];  
      }  
      o[this.name].push(this.value || '');  
    } else {  
      o[this.name] = this.value || '';  
    }  
  });  
  return o;  
};
(function($) {
    $.fn.serializeJson = function(prefix) {
        var result = {};
        var n = prefix ? (prefix + '.') : "";
        var arrayTypes = this["arrayTypes"];
        var array = this.serializeArray();
        var datetimeTypes = this["datetimeTypes"] || [];
        for (var i = 0; i < array.length; i++) {
            if ($.inArray(array[i].name, datetimeTypes) >= 0) {
                if (array[i].value) {
                    array[i].value = new Date(array[i].value.replace(/-/g, "/")).getTime();
                } else {
                    delete array[i].name;
                }
            }
        }
        $(array).each(function() {
            if (!this.name || this.name.indexOf(n) != 0) return;
            var name = this.name.substring(n.length);
            var idot = name.indexOf('.');
            if (idot > 0) {
                var n1 = name.substring(0, idot);
                var n2 = name.substring(idot + 1);
                if (!result[n1]) result[n1] = {};
                result[n1][n2] = this.value;
            } else if (result[name]) {
                if ($.isArray(result[name])) {
                    result[name].push(this.value);
                } else {
                    result[name] = [result[name], this.value];
                }
            } else {
                result[name] = this.value;
            }
        });
        if (!arrayTypes) return result;
        for (var i = 0; i < arrayTypes.length; i++) {
            var n = arrayTypes[i];
            if (!result[n]) {
                delete result[n];
            } else if (!$.isArray(result[n])) {
                result[n] = [result[n]];
            }
        }
        return result;
    };

    var privateJsonString = function(object) {
        var type = typeof object;
        if ('object' == type && Array == object.constructor) {
            type = 'array';
        }
        switch (type) {
            case 'number':
                return object ? ("" + object) : "0";
            case 'string':
                return '"' + object.replace(/(\\|\")/g, "\\$1") + '"';
            case 'object':
                var results = [];
                for (var property in object) {
                    results.push(property + ':' + privateJsonString(object[property]));
                }
                return '{' + results.join(',') + '}';
            case 'array':
                var results = [];
                for (var i = 0; i < object.length; i++) {
                    results.push(object[i] ? privateJsonString(object[i]) : "null");
                }
                return '[' + results.join(',') + ']';
            default :
                return (object === undefined) ? ("" + object) : "null";
        }
    };
    $.objectToString = privateJsonString;
    $.fn.serializeJsonString = function(prefix) {
        return privateJsonString(this.serializeJson(prefix));
    };

})(jQuery);
/**
* 格式化日期 
* 调用方式： var str = new Date().Format("yyyy-MM-dd HH:mm:ss");
*/
Date.prototype.Format = function (fmt) { //author: meizz  
   var o = { 
       "M+": this.getMonth() + 1, //月份  
       "d+": this.getDate(), //日  
       "H+": this.getHours(), //小时  
       "m+": this.getMinutes(), //分  
       "s+": this.getSeconds(), //秒  
       "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
       "S": this.getMilliseconds() //毫秒  
   }; 
   if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); 
   for (var k in o) 
       if (new RegExp("(" + k + ")").test(fmt)) 
           fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 
   return fmt; 
} ;
/**
 * ajax 默认公共属性
 */
$.ajaxSetup({
  cache: false,
  async: false,
});

/**
 * 删除数组元素
 */
Array.prototype.remove=function(dx){ 
    if(isNaN(dx)||dx>this.length){return false;} 
    for(var i=0,n=0;i<this.length;i++) 
    { 
        if(this[i]!=this[dx]) 
        { 
            this[n++]=this[i] 
        } 
    } 
    this.length-=1 
}

/**
 * 校验变量值是否为null或空字符（undefined、null、"" 返回false,其他返回true）
 */
function isNotBlank(value){
	if(value == undefined){
		return false;
	}
	if(value == "undefined"){
		return false;
	}
	if(value == null){
		return false;
	}
	if(value == "null"){
		return false;
	}
	if(value === ""){
		return false;
	}
	return true;
}
//检查是不是数组
function isArray(arg){
  return Object.prototype.toString.call(arg) === '[object Array]';
}
/**
 * checkbox单选
 * @param checkboxName
 * @param form
 */
function singleCheckbox(checkboxName, form) {  
    if (checkboxName == null) return;  
    var f = form || document.forms[0];  
    checkboxs = document.getElementsByName(checkboxName);  
      
    for(i = 0; i < checkboxs.length; i++){  
        checkboxs[i].onclick = function(){  
            for (j = 0; j < checkboxs.length; j++ ){  
                if (this.value != checkboxs[j].value && checkboxs[j].checked == true){  
                    checkboxs[j].checked = false;  
                }  
            }  
        }  
    }  
}

/**
 * 字符串转日期
 * 格式：yyyy-MM-dd HH:mm:ss
 *     yyyy-MM-dd
 * @param strDate
 * @returns {Date}
 */
function strToDate(strDate){
	if(!strDate) return;
	var o = new Date(strDate.replace(/-/g,"/"));
	return o;
	
}

//修改baseObj对象中name字段的日期时间格式值为long型
function chgDateToLong(baseObj,name){
	if(baseObj[name] && baseObj[name]!="")
		baseObj[name] = strToDate(baseObj[name]).getTime();
	else
		baseObj[name] = "";
}